package fu.capstone.hanoicityguide.presentation.fragment.transportation;

import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import fu.capstone.hanoicityguide.R;
import fu.capstone.hanoicityguide.business.bo.cyclo.CycloBO;
import fu.capstone.hanoicityguide.business.bo.cyclo.CycloBOImp;
import fu.capstone.hanoicityguide.business.model.Cyclo;
import fu.capstone.hanoicityguide.common.utility.CycloDialog;
import fu.capstone.hanoicityguide.presentation.adapter.ListCycloAdapter;

public class FragmentCycloTab extends Fragment{

	private CycloBO cycloBO;
	private ArrayList<Cyclo> arrCyclo;
	private CycloDialog cycloDialog;
	
	@Override
	public View onCreateView(LayoutInflater inflater, final ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View cycloTab = inflater.inflate(R.layout.fragment_list_cyclo, container, false);
		
		ListView listCyclo = (ListView) cycloTab.findViewById(R.id.listCyclo);
		cycloBO = new CycloBOImp(container.getContext());
		
		arrCyclo = new ArrayList<Cyclo>();
		arrCyclo = cycloBO.listCyclo("", "");
		
		listCyclo.setAdapter(new ListCycloAdapter(getActivity(), 
				R.layout.adapter_list_cyclo, arrCyclo));
		
		listCyclo.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				cycloDialog = new CycloDialog(container.getContext());
				cycloDialog.showDialog(arrCyclo.get(position).getPhoneNumber(), arrCyclo.get(position).getWebsite());
			}
			
		});
		
		return cycloTab;
	}
}
